#pragma once

#include "csr.h"
#include "asm.h"

#define csr_set(csr, val)                                  \
    ({                                                     \
        unsigned long __v = (unsigned long)(val);          \
        __asm__ __volatile__("csrs " __ASM_STR(csr) ", %0" \
                             : : "rK"(__v)                 \
                             : "memory");                  \
    })

#define csr_clear(csr, val)                                \
    ({                                                     \
        unsigned long __v = (unsigned long)(val);          \
        __asm__ __volatile__("csrc " __ASM_STR(csr) ", %0" \
                             : : "rK"(__v)                 \
                             : "memory");                  \
    })
